import 'package:flutter/material.dart';
import 'package:flutter_demo/tmac/widget/DirectionEnum.dart';

// ignore: must_be_immutable
class DrawableTextWidget extends StatelessWidget {
  Widget title;
  Widget icon;
  double iconPadding;
  var direction;
  GestureTapCallback press;

  DrawableTextWidget(
      {Key key,
      @required this.title,
      @required this.icon,
      this.press,
      this.iconPadding = 5,
      this.direction = Direction.Left});

  Widget getWidget() {
    Widget widget;
    switch (direction) {
      case Direction.Left:
        widget = Row(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            icon,
            Padding(
              padding: EdgeInsets.only(left: iconPadding),
              child: title,
            )
          ],
        );
        break;

      case Direction.Top:
        widget = Column(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            icon,
            Padding(
              padding: EdgeInsets.only(top: iconPadding),
              child: title,
            )
          ],
        );
        break;

      case Direction.Right:
        widget = Row(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            title,
            Padding(
              padding: EdgeInsets.only(left: iconPadding),
              child: icon,
            )
          ],
        );
        break;

      case Direction.Bottom:
        widget = Column(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            title,
            Padding(
              padding: EdgeInsets.only(top: iconPadding),
              child: icon,
            )
          ],
        );
        break;
      default:
        widget = Row(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            icon,
            Padding(
              padding: EdgeInsets.only(left: iconPadding),
              child: title,
            )
          ],
        );
        break;
    }
    return widget;
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: press,
      child: Container(child: getWidget()),
    );
  }
}
